﻿using ArticleandSiteData;
using ModelClassLibrary;
using SplitViewOptions.BusinessControl;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Networking.BackgroundTransfer;
using Windows.Storage;
using Windows.Storage.Pickers;
using System.Threading;
using Windows.Devices.Geolocation;
using modle;
using Newtonsoft.Json;
using System.Collections.ObjectModel;
using Windows.Graphics.Display;
using Windows.UI.ViewManagement;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace SplitViewOptions
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class Desktop : Page
    {
        public Desktop()
        {
            this.InitializeComponent();
            if (App.Isnightmode)
            {
                this.Background = new SolidColorBrush(Colors.Black);
              //  this.Opacity = 0.2;
            }
            this.Loaded += Desktop_Loaded;
        }

        private async void Desktop_Loaded(object sender, RoutedEventArgs e)
        {
            if (pivot.SelectedIndex == 0)
            {
            await  GetchildmessageData();
                Flyout f = this.channelbtn.Flyout as Flyout;
                if (f != null)
                {
                    f.ShowAt(channelbtn);
                    //Flyout.ShowAttachedFlyout(channelbtn);
                }
             await   Getlocation();
            }
        }

        DesktopSitesResult desktopone;
        private async void getusersDesktopsite()
        {
            try
            {
                if (App.Loginuser != null)
                {
                    //desktopone = await BmobWebsiteData.GetOneuserwebsitesinfoone<DesktopSitesResult>(App.desktopsites);
                    //if (desktopone == null) return;
                    //var resultone = from inisn in desktopone.results
                    //                where inisn.userid == App.loginuser.objectId
                    //                select inisn;
                    //if (resultone == null) return;
                    //if (resultone.Count() > 0)
                    //{
                    //    var a = resultone.First();
                    //    App.objectid = a.objectId;

                    //    DesktopsitesList one = a;
                    //    string[] urlarray = one.usersites.Split(',');
                    //    string[] namearray = one.usersitesname.Split(',');
                    //    List<Info> resulist = new List<Info>();
                    //    for (int i = 0; i < urlarray.Count(); i++)
                    //    {
                    //        if (!string.IsNullOrEmpty(urlarray[i]))
                    //        {
                    //            Info oneinfo = new Info();
                    //            oneinfo.dataurl = urlarray[i];
                    //            oneinfo.text = namearray[i];
                    //            resulist.Add(oneinfo);
                    //        }
                    //    }
                    //    await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { navigateviewer.ItemsSource = resulist; ; });

                    //    Debug.WriteLine("data from web");
                    //}
                    //else
                    //{
                    //    await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { navigateviewer.ItemsSource = App.getDesktopsites(); });

                    //}
                    string url = App.Desktopsites + "/?where={" +"\"" +"userid"+"\"" + ":" +"\""+ App.Loginuser.objectId+"\""+"}";

                    DesktopSitesResult onedesktopone = await BmobWebsiteData.GetOneuserwebsitesinfoone<DesktopSitesResult>(url);
                    if (onedesktopone != null&&onedesktopone.results.Count>0)
                    {

                        var a = onedesktopone.results.FirstOrDefault();
                        App.Objectid = a.objectId;

                        DesktopsitesList one = a;
                        string[] urlarray = one.usersites.Split(',');
                        string[] namearray = one.usersitesname.Split(',');
                        List<Info> resulist = new List<Info>();
                        for (int i = 0; i < urlarray.Count(); i++)
                        {
                            if (!string.IsNullOrEmpty(urlarray[i]))
                            {
                                Info oneinfo = new Info();
                                oneinfo.dataurl = urlarray[i];
                                oneinfo.text = namearray[i];
                                resulist.Add(oneinfo);
                            }
                        }
                        await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { navigateviewer.ItemsSource = resulist; ; });

                        Debug.WriteLine("data from web");
                    }
                    else
                    {
                        await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { navigateviewer.ItemsSource = App.GetDesktopsites(); });
                    }
                
                }

                else
                {
                    await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { navigateviewer.ItemsSource = App.GetDesktopsites(); });
                    //string str = await HtmlUsedFunction.gethtmlstring("http://live3.win007.com/index2in1.aspx?id=1");
                    //  Debug.WriteLine(str);
                }
            }
            catch(Exception ex)
            {
            }
        }
        protected  override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.NavigationMode == NavigationMode.New)
            {
                Task desktoptask = new Task(getusersDesktopsite);
                desktoptask.Start();
                 }
                else
                {
                if (App.Loginuser != null)
                {
                    Task logintask = new Task(getusersDesktopsite);
                    logintask.Start();
                }
                else
                {
                    navigateviewer.ItemsSource = App.GetDesktopsites();
                }
                   
                    //string str = await HtmlUsedFunction.gethtmlstring("http://live3.win007.com/index2in1.aspx?id=1");
                    //  Debug.WriteLine(str);
                }
            init();
            App.Titlebox.Text = string.Empty;
            base.OnNavigatedTo(e);
        }
        protected  override void OnNavigatedFrom(NavigationEventArgs e)
        {
             if(navigateviewer.ItemsSource!=null)
            {
                App.Itemssites = navigateviewer.ItemsSource as ObservableCollection<Info>;
            }           
            base.OnNavigatedFrom(e);
        }
      
        private void Border_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Border obj = sender as Border;
            Info oneinfo = obj.DataContext as Info;

            App.Currenturl = new Uri(oneinfo.dataurl, UriKind.RelativeOrAbsolute);
            this.Frame.Navigate(typeof(HomePage));

        }
        private void channelbtn_Click(object sender, RoutedEventArgs e)
        {

        }

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            AddSitesContentDialog one = new AddSitesContentDialog();
         await   one.ShowAsync();
            navigateviewer.ItemsSource = App.GetDesktopsites();
        }
        private void videobtnclick(object sender, RoutedEventArgs e)
        {
            Flyout f = this.channelbtn.Flyout as Flyout;
            if (f != null)
            {
                f.Hide();
            }
            string str = string.Empty;
            if (App.Ismobile)
            {

                if ((sender as Button).Content.ToString() == "视听")
                {
                    str = "http://hao567.github.io/v.html";
                }
                else if ((sender as Button).Content.ToString() == "学习")
                {
                    str = "http://hao567.github.io/learn.html";
                }
                else if ((sender as Button).Content.ToString() == "阅读")
                {
                    str = "http://hao567.github.io/Read.html";
                }
                else if ((sender as Button).Content.ToString() == "社区")
                {
                    str = "http://hao567.github.io/Shequ.html";
                }
                else if ((sender as Button).Content.ToString() == "科技")
                {
                    str = "http://hao567.github.io/Keji.html";
                }
                else if ((sender as Button).Content.ToString() == "体育")
                {
                    str = "http://hao567.github.io/Sports.html";
                }
                else if ((sender as Button).Content.ToString() == "军事")
                {
                    str = "http://hao567.github.io/Armitary.html";
                }
                else if ((sender as Button).Content.ToString() == "华人")
                {
                    str = "http://hao567.github.io/Haiwai.html";
                }
                else if ((sender as Button).Content.ToString() == "股票")
                {
                    str = "http://hao567.github.io/stock.html";
                }
                else if ((sender as Button).Content.ToString() == "聚分享")
                {
                    str = "http://hao567.github.io/share.html";
                }
                else if ((sender as Button).Content.ToString() == "生活")
                {
                    str = "http://hao567.github.io/life.html";
                }
                else if ((sender as Button).Content.ToString() == "游戏")
                {
                    str = "http://hao567.github.io/game.html";
                }
                else if ((sender as Button).Content.ToString() == "娱乐")
                {
                    str = "http://hao567.github.io/e.html";
                }
                else if ((sender as Button).Content.ToString() == "购物")
                {
                    str = "http://hao567.github.io/sale.html";
                }
                else if ((sender as Button).Content.ToString() == "开发")
                {
                    str = "http://hao567.github.io/code.html";
                }
                else if ((sender as Button).Content.ToString() == "聊天")
                {
                    str = "http://hao567.github.io/talk.html";
                }
                else if ((sender as Button).Content.ToString() == "其他")
                {
                    str = "http://hao567.github.io/t.html";
                }
                else if ((sender as Button).Content.ToString() == "应用中心")
                {
                    str = "http://datiancun.net/portal.php";
                }
                else if ((sender as Button).Content.ToString() == "uwp之家")
                {
                    str = "http://datiancun.net/portal.php";
                }
                else if ((sender as Button).Content.ToString() == "小游戏")
                {
                    str = "http://hao567.github.io/weigame.html";
                }
                else if ((sender as Button).Content.ToString() == "酷七市场")
                {
                    str = "http://app.ruanfenquan.com/";
                }
                else if ((sender as Button).Content.ToString() == "Foreign")
                {
                    str = "http://hao567.github.io/f.html";
                }
                else if ((sender as Button).Content.ToString() == "国外")
                {
                    str = "http://hao567.github.io/f.html";
                }
                else if ((sender as Button).Content.ToString() == "官媒")
                {
                    str = "http://hao567.github.io/dang.html";
                }
                else if ((sender as Button).Content.ToString() == "城市")
                {
                    str = "http://hao567.github.io/city.html";
                }
                else if ((sender as Button).Content.ToString() == "笑话")
                {
                    str = "http://hao567.github.io/joke.html";
                }
                else
                {

                    str = "http://www.hao123.com/video";
                }
            }
            else
            {
                if ((sender as Button).Content.ToString() == "视听")
                {
                    str = "http://www.hao123.com/video";
                }
                else if ((sender as Button).Content.ToString() == "小游戏")
                {
                    str = "http://hao567.github.io/weigame.html";
                }
                else if ((sender as Button).Content.ToString() == "国外")
                {
                    str = "http://hao567.github.io/f.html";
                }
                else if ((sender as Button).Content.ToString() == "官媒")
                {
                    str = "http://hao567.github.io/dang.html";
                }
                else if ((sender as Button).Content.ToString() == "城市")
                {
                    str = "http://hao567.github.io/city.html";
                }
                else if ((sender as Button).Content.ToString() == "笑话")
                {
                    str = "http://hao567.github.io/joke.html";
                }
                else if ((sender as Button).Content.ToString() == "Foreign")
                {
                    str = "http://hao567.github.io/f.html";
                }
                else if ((sender as Button).Content.ToString() == "学习")
                {
                    str = "http://www.copyedu.com/";
                }
                else if ((sender as Button).Content.ToString() == "娱乐")
                {
                    str = "http://hao567.github.io/e.html";
                }
                else if ((sender as Button).Content.ToString() == "购物")
                {
                    str = "http://hao567.github.io/sale.html";
                }
                else if ((sender as Button).Content.ToString() == "股票")
                {
                    str = "http://hao.360.cn/gupiaowz.html";
                }
                else if ((sender as Button).Content.ToString() == "聚分享")
                {
                    str = "http://hao567.github.io/share.html";
                }
                else if ((sender as Button).Content.ToString() == "聊天")
                {
                    str = "http://hao567.github.io/talk.html";
                }
                else if ((sender as Button).Content.ToString() == "uwp之家")
                {
                    str = "http://datiancun.net/portal.php";
                }
                else if ((sender as Button).Content.ToString() == "酷七市场")
                {
                    str = "http://app.ruanfenquan.com/";
                }
                else if ((sender as Button).Content.ToString() == "阅读")
                {
                    str = "http://hao567.github.io/Read.html";
                }
                else if ((sender as Button).Content.ToString() == "社区")
                {
                    str = "http://hao567.github.io/Shequ.html";
                }
                else if ((sender as Button).Content.ToString() == "科技")
                {
                    str = "http://hao567.github.io/Keji.html";
                }
                else if ((sender as Button).Content.ToString() == "体育")
                {
                    str = "http://hao567.github.io/Sports.html";
                }
                else if ((sender as Button).Content.ToString() == "军事")
                {
                    str = "http://hao567.github.io/Armitary.html";
                }
                else if ((sender as Button).Content.ToString() == "华人")
                {
                    str = "http://hao567.github.io/Haiwai.html";
                }
                else if ((sender as Button).Content.ToString() == "其他")
                {
                    str = "http://hao567.github.io/t.html";
                }
                else if ((sender as Button).Content.ToString() == "生活")
                {
                    str = "http://hao.360.cn/shenghuowz.html";
                }
                else if ((sender as Button).Content.ToString() == "游戏")
                {
                    str = "http://game.2345.com/site.htm";
                }
                else if ((sender as Button).Content.ToString() == "小游戏")
                {
                    str = "http://hao567.github.io/weigame.html";
                }
                else if ((sender as Button).Content.ToString() == "开发")
                {
                    str = "http://hao567.github.io/code.html";
                }
                else if ((sender as Button).Content.ToString() == "应用中心")
                {
                    str = "http://datiancun.net/portal.php";
                }
                else
                {
                    str = "http://www.hao123.com/video";
                }
            }
            App.Currenturl = new Uri(str, UriKind.RelativeOrAbsolute);
            this.Frame.Navigate(typeof(HomePage));
            //   homewebview.Navigate(App.currenturl);
        }

        private void withoutpicbtn_Click(object sender, RoutedEventArgs e)
        {
            Flyout f = this.morebtn.Flyout as Flyout;
            if (f != null)
            {
                f.Hide();

                //rootPage.NotifyUser("You bought an item!", NotifyType.StatusMessage);
            }
            App.Iswithoutpicmode = true;
            App.Isdownloadstirngmode = true;
        }

        private void readmodebtn_Click(object sender, RoutedEventArgs e)
        {
            Flyout f = this.morebtn.Flyout as Flyout;
            if (f != null)
            {
                f.Hide();

                //rootPage.NotifyUser("You bought an item!", NotifyType.StatusMessage);
            }
            App.Readmode = true;
            App.Isdownloadstirngmode = true;
        }

        private void picbtn_Click(object sender, RoutedEventArgs e)
        {
            App.Iswithoutpicmode = false;
         
        }

        private async void btnclickupload_Click(object sender, RoutedEventArgs e)
        {
            string userid = string.Empty;
            string username = string.Empty;
            string sitesurls = string.Empty;
            string sitenames = string.Empty;
            if (App.Loginuser != null)
            {
                userid = App.Loginuser.objectId;
                username = App.Loginuser.username;

            }
            else
            {
                await App.showmessage("请先登录");
                //MessageDialog one = new MessageDialog("没登录"); 
                //await one.ShowAsync();
                return;
            }
           await    App.Addoruodatedesktopsites();
        }

        private async void createdownload(object sender, RoutedEventArgs e)
        {
            DownloadContentDialog doanload = new DownloadContentDialog("");

            await doanload.ShowAsync();
        }
        private void daymodebtn_Click(object sender, RoutedEventArgs e)
        {  
            App.Isnightmode = false;
            Flyout f = this.morebtn.Flyout as Flyout;
            if (f != null)
            {
                f.Hide();

                //rootPage.NotifyUser("You bought an item!", NotifyType.StatusMessage);
            }
            App.Isnightmode = false;
           // homewebview.DefaultBackgroundColor = Colors.White;
            //   homewebview.Refresh();
        }
        private void nightmodebtn_Click(object sender, RoutedEventArgs e)
        {
            Flyout f = this.morebtn.Flyout as Flyout;
            if (f != null)
            {
                f.Hide();

                //rootPage.NotifyUser("You bought an item!", NotifyType.StatusMessage);
            }
            this.Background = new SolidColorBrush(Colors.Black);
            this.Opacity = 0.2;
            //homewebview.DefaultBackgroundColor = Colors.Black;
            //   homewebview.Refresh();
            App.Isnightmode = true;
        }

        private void backgroundmodebtn_Click(object sender, RoutedEventArgs e)
        {
            Flyout f = this.morebtn.Flyout as Flyout;
            if (f != null)
            {
                f.Hide();

                //rootPage.NotifyUser("You bought an item!", NotifyType.StatusMessage);
            }
            App.Isbackgroundmode = true;
        }

        private void mobilemodebtn_Click(object sender, RoutedEventArgs e)
        {
            Flyout f = this.morebtn.Flyout as Flyout;
            if (f != null)
            {
                f.Hide();

                //rootPage.NotifyUser("You bought an item!", NotifyType.StatusMessage);
            }
            App.Ismobile = true;
        }

        private void pcbtn_Click(object sender, RoutedEventArgs e)
        {
            Flyout f = this.morebtn.Flyout as Flyout;
            if (f != null)
            {
                f.Hide();

                //rootPage.NotifyUser("You bought an item!", NotifyType.StatusMessage);
            }
            App.Ismobile = false; ;
        }

        private void fulbtn_Click(object sender, RoutedEventArgs e)
        {
            Flyout f = this.morebtn.Flyout as Flyout;
            if (f != null)
            {
                f.Hide();

                //rootPage.NotifyUser("You bought an item!", NotifyType.StatusMessage);
            }
            App.Isfully = true;
        }

        private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
        {

            ToggleSwitch o = sender as ToggleSwitch;
            string str = o.Header.ToString();
            if(str=="全屏模式")
            {
                if(o.OnContent.ToString()=="开")
                {
                    App.Isfully = true;
                    App.Mainmenugrid.Visibility = Visibility.Collapsed;
                }
                else
                {
                    App.Isfully = false;
                    App.Mainmenugrid.Visibility = Visibility.Visible;
                }
            }
            if (str == "防锁屏")
            {
                if (o.OnContent.ToString() == "开")
                {
                    App.Isunlocksmode = true;
                }
                else
                {
                    App.Isunlocksmode = false;
                }
            }
            if (str == "pc模式")
            {
                if (o.OnContent.ToString() == "开")
                {
                    App.Ismobile = false;
                }
                else
                {
                    App.Ismobile = true;

                }
               
                DisplayInformation.AutoRotationPreferences = DisplayOrientations.LandscapeFlipped | DisplayOrientations.Landscape;
                //homewebview.DefaultBackgroundColor = Colors.Black;
                //   homewebview.Refresh();

            }
            if (str == "夜间模式")
            {
                if (o.OnContent.ToString() == "开")
                {
                    App.Isnightmode = true;
                    lg.Background = new SolidColorBrush(Colors.Black);
                    this.channelbtn.Foreground = new SolidColorBrush(Colors.WhiteSmoke);
                    this.appcenter.Foreground = new SolidColorBrush(Colors.WhiteSmoke);
                    this.download.Foreground = new SolidColorBrush(Colors.WhiteSmoke);
                    this.morebtn.Foreground = new SolidColorBrush(Colors.WhiteSmoke);
                    this.setbtn.Foreground = new SolidColorBrush(Colors.WhiteSmoke);
                }
                else
                {
                    App.Isnightmode = false;
                    this.Background = new SolidColorBrush(Colors.WhiteSmoke);
                  
                }

            }
            if (str == "后台模式")
            {
                if (o.OnContent.ToString() == "开")
                {
                    App.Isbackgroundmode = true;
                }
                else
                {
                    App.Isbackgroundmode = false;
                }
            }
            if (str == "无图模式")
            {
                if (o.OnContent.ToString() == "开")
                {
                    App.Iswithoutpicmode = true;
                }
                else
                {

                    App.Iswithoutpicmode = false;
                }
            }
        }
        private void init()
        {
            if(App.Isfully)
            {
                fulmode.IsOn = true;
            }
            else
            {
                fulmode.IsOn = false;
            }
        
            if (App.Isnightmode)
            {
                nightmode.IsOn = true;
            }
            else
            {
                nightmode.IsOn = false;
            }
            if (App.Ismobile)
            {
                pcmode.IsOn = false;
            }
            else
            {
                pcmode.IsOn = true;
            }
            if (App.Iswithoutpicmode)
            {
                nonepicmode.IsOn = true;
            }
            else
            {
                nonepicmode.IsOn = false;
            }
            if (App.Isunlocksmode)
            {

                unlockscreen.IsOn = true;
            }
            else
            {
                unlockscreen.IsOn = false;
            }
        }
        #region 下载功能
        DownloadOperation downloadOperation;
        CancellationTokenSource cancellationToken;
        string url = string.Empty;
        Windows.Networking.BackgroundTransfer.BackgroundDownloader backgroundDownloader = new Windows.Networking.BackgroundTransfer.BackgroundDownloader();
        

        private void cancledoawload_Click(object sender, RoutedEventArgs e)
        {

        }


        #endregion

        private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void uppic(object sender, RoutedEventArgs e)
        {
            this.Frame.Navigate(typeof(UploadpicPage));
        }
        public async Task<Geoposition> GetPosition()
        {
            //请求对位置的访问权
            var accessStatus = await Geolocator.RequestAccessAsync();
            //此时，窗口会弹出提示是否允许应用访问位置，如果用户不允许则抛出异常
            //不要抛异常 ——林德熙
            if (accessStatus != GeolocationAccessStatus.Allowed) throw new Exception();
            //实例化定位类，并设置经纬度精确度（单位：米），一般为零，为保护用户隐私，建议减少精确度
            var geolocator = new Geolocator { DesiredAccuracyInMeters = 0 };
            //异步获取设备位置，并将位置保存到变量中（Geoposition类型）
            var position = await geolocator.GetGeopositionAsync();
            //异步获取位置，保存到变量中


            //返回位置
            return position;
        }
        private async Task Getlocation()
        {
            try
            {

                //await App.showmessage("定位中");
             
                var position = await GetPosition();
                //维度
                double lat = position.Coordinate.Point.Position.Latitude;
                //经度
                double lon = position.Coordinate.Point.Position.Longitude;
               
                //await App.showmessage("经纬度：" + lat.ToString() + "," + lon.ToString());
                string geocodeurl = "http://api.map.baidu.com/geocoder/v2/?ak=6kvn8vZN6KFaxcMErHGLb7H5&location=" + lat.ToString() + "," + lon.ToString() + "&output=json&pois=0";
                HttpClient adressclient = new HttpClient();

                var myRequest = new HttpRequestMessage(HttpMethod.Get, geocodeurl);
                myRequest.Version = Version.Parse("1.1");
                Debug.WriteLine(myRequest.Version.ToString());
                // await App.showmessage("获取地址中");
              
                var response = await adressclient.SendAsync(myRequest);
                string streamcontent = await response.Content.ReadAsStringAsync();
                BaiduAdresslocatejson deserializedProduct = (BaiduAdresslocatejson)JsonConvert.DeserializeObject(streamcontent, typeof(BaiduAdresslocatejson));
                string distrtict = deserializedProduct.result.addressComponent.district;
                string cityname = deserializedProduct.result.addressComponent.city;
                // L.Text = deserializedProduct.result.formatted_address;
                App.Curruntprovince = deserializedProduct.result.addressComponent.province;
                if (App.Curruntprovince.Contains("省"))
                {
                    App.Curruntprovince=  App.Curruntprovince.Replace("省", string.Empty);
                    ObservableCollection<Info> navlist = navigateviewer.ItemsSource as ObservableCollection<Info>;
                    string provinceurl = "http://hao567.github.io/" + App.Curruntprovince + ".html";
                    navlist.Add(new Info() { text = App.Curruntprovince, dataurl = provinceurl });
                    navigateviewer.ItemsSource = navlist;
                }
                if (App.Curruntprovince.Contains("市"))
                {
                    App.Curruntprovince = App.Curruntprovince.Replace("市", string.Empty);
                    ObservableCollection<Info> navlist = navigateviewer.ItemsSource as ObservableCollection<Info>;
                    string provinceurl = "http://hao567.github.io/" + App.Curruntprovince + ".html";
                    navlist.Add(new Info() { text = App.Curruntprovince, dataurl = provinceurl });
                    navigateviewer.ItemsSource = navlist;
                }
            }
            catch (Exception ex) { }
        }


        public static string childmessageAPI = "https://api.bmob.cn/1/classes/message";
        public async Task<messageinfoList> GetchildmessageData()
        {
            var myClient = new HttpClient();
            var myRequest = new HttpRequestMessage(HttpMethod.Get, childmessageAPI);
            myRequest.Version = Version.Parse("1.1");
            myRequest.Headers.Add("X-Bmob-Application-Id", App.Applicationid);
            myRequest.Headers.Add("X-Bmob-REST-API-Key", App.Restkeyid);
            Debug.WriteLine(myRequest.Version.ToString());
            var response = await myClient.SendAsync(myRequest);
            string streamcontent = await response.Content.ReadAsStringAsync();
            messageinfoList resualist = null;
            resualist = (messageinfoList)JsonConvert.DeserializeObject(streamcontent, typeof(messageinfoList));
            messageinfoview.ItemsSource = resualist.results;
            var r = from a in resualist.results select a.url;         
            return resualist;
        }
        private void messagetapped(object sender, TappedRoutedEventArgs e)
        {
            string url = (((sender as TextBlock).DataContext) as messageinfo).url;
            if (string.IsNullOrEmpty(url)) return;
            App.Currenturl = new Uri(url, UriKind.RelativeOrAbsolute);
            this.Frame.Navigate(typeof(HomePage));
        }
    }
    public class messageinfo
    {

        public string url { get; set; }
        public string message { get; set; }
        public string sitetype { get; set; }
        public string logo { get; set; }
       
        public string objectId { get; set; }
        public string createdAt { get; set; }
        public string updatedAt { get; set; }
    }
    public class messageinfoList
    {
        public List<messageinfo> results { get; set; }
    }

}
